package cn.ekuma.pos.pda.order;

import cn.ekuma.epos.android.finder.CustomerFinderActivate;
import cn.ekuma.epos.android.finder.LocationFinderActivate;
import cn.ekuma.epos.android.finder.UserFinderActivate;
import cn.ekuma.pos.android.erp.R;
import cn.ekuma.pos.pda.finder.OrderTypeFinderActivator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public abstract class OrderFilter extends LinearLayout{
	public static final int  SELECT_USER=0;
	public static final int  SELECT_CUSTOMER=1;
	public static final int  SELECT_LOCATION=2;
	public static final int  SELECT_ORDERTYPE=3;
	
	protected Button btnCustomer,btnOrderType,btnUser,btnLocation;
	
	public OrderFilter(Context context) {
		super(context);
		init(context);
	}
	
	public OrderFilter(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
    private void init(final Context context) {
    	View mainView = LayoutInflater.from(context).inflate( R.layout.order_filter, this); 
    	 btnCustomer=(Button) mainView.findViewById(R.id.btnCustomer);
    	btnCustomer.setOnClickListener(new OnClickListener(){
			
			public void onClick(View v) {	
				fireStartActivateForResert(CustomerFinderActivate.class,SELECT_CUSTOMER);
			}
    	});
    	
    	btnOrderType=(Button) mainView.findViewById(R.id.btnOrderType);
    	btnOrderType.setOnClickListener(new OnClickListener(){
			
			public void onClick(View v) {
				fireStartActivateForResert(OrderTypeFinderActivator.class,SELECT_ORDERTYPE);
			}
    	});
    	
    	btnUser=(Button) mainView.findViewById(R.id.btnUser);
    	btnUser.setOnClickListener(new OnClickListener(){
			
			public void onClick(View v) {
				fireStartActivateForResert(UserFinderActivate.class,SELECT_USER);
			}
    	});
    	
    	btnLocation=(Button) mainView.findViewById(R.id.btnLocation);
    	btnLocation.setOnClickListener(new OnClickListener(){
			
			public void onClick(View v) {
				fireStartActivateForResert(LocationFinderActivate.class,SELECT_LOCATION);
			}
    	});
    }

    public abstract void fireStartActivateForResert(Class finderActivate,int returnCode);
    
    
    public void resertValues(){
    	btnCustomer.setText(null);
    	btnOrderType.setText(null);
    	btnUser.setText(null);
    	btnLocation.setText(null);
    }
    
    
    public void setTextValue(int returnCode,String value){
    	switch(returnCode){
    	   case SELECT_CUSTOMER:
    		   btnCustomer.setText(value);
    		   break;
    	   case SELECT_ORDERTYPE:
    		   btnOrderType.setText(value);
    		   break;
    	   case SELECT_USER:
    		   btnUser.setText(value);
    		   break;
    	   case SELECT_LOCATION:
    		   btnLocation.setText(value);
    		   break;
    	}
    }
}
